# -*- coding:utf8 -*-
from xxqg.utils import *
import re
from xxqg.db import *
import json


class spider():
    def __init__(self,url):
        self.url = url
        pass

    def index(self):
        query = (urls.update(filestatus=0).where(urls.filestatus>=5))
        query.execute()

        fullurl,savepath = geturlandsavepath(self.url,'')
        html = gethtml(self.url)
        html = downres(self.url,html,0)
        savehtml(savepath,html)

    def html(self,model):
        url = model.url
        savepath = model.savepath

        html = gethtml(url)
        html = re.sub(r'\s*"',r'"',html)
        html = re.sub(r"\s*'",r"'",html)
        html = downres(url,html,model.deepth)
        savehtml(savepath,html)

